package com.ht.config;

import com.ht.controller.PublicOutpatientController;
import com.ht.data.Result;
import com.ht.domain.bo.TbScheduleBO;
import com.ht.service.ScheduleService;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@PersistJobDataAfterExecution//将JobDataMap进行持久化
@DisallowConcurrentExecution //禁止并发
public class QuertzJob extends QuartzJobBean {
    @Autowired
    private PublicOutpatientController publicOutpatientController;
    @Autowired
    private ScheduleService scheduleService;
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
        String jobKey = jobDataMap.getString("jobKey");

        List<TbScheduleBO> boList = scheduleService.   queryAll();
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(date);
        for (TbScheduleBO bo : boList) {
            publicOutpatientController.queryPublicById(bo.getDoctorId(),format);
        }
    }
}
